#include "mylabel.h"
#include <QDebug>
#include <QMouseEvent>

myLabel::myLabel(QWidget *parent) : QLabel(parent)
{
    setMouseTracking(true);
}
void myLabel::enterEvent(QEvent *event)
{
    qDebug() << "鼠标进入";
}
void myLabel::leaveEvent(QEvent *)
{
    qDebug() << "鼠标离开";
}
void myLabel::mouseReleaseEvent(QMouseEvent *ev)
{
    qDebug() << "鼠标释放";
}
void myLabel::mouseMoveEvent(QMouseEvent *ev)
{
    if(ev->buttons() & Qt::RightButton)
    {
        qDebug() << "右键移动";
        QString str = QString("鼠标右键按下移动 x = %1 y = %2").arg(ev->x()).arg(ev->y());
        qDebug() << str;
    }
    QString str = QString("没有按下移动 x = %1 y = %2").arg(ev->x()).arg(ev->y());
    qDebug() << str;
}
bool myLabel::event(QEvent *e)
{
    if(e->type()==QEvent::MouseButtonRelease)
    {
        QMouseEvent * ev = static_cast<QMouseEvent *>(e);
        qDebug() << "ev->type()==QEvent::";
        // true代表用户自己处理事件，不向下分发
        return true;
    }
    return QLabel::event(e);
}
